package ajjj.kiviq;


/**
 * Updated 2011-10-05, Jonatan
 * Added more constants and public/resource files
 * and helper method
 * 
 * Updated 2011-10-08, Jonatan
 * Updated the isPublic method and ResourceFiles array
 * to support the javax.faces.resource resources
 * 
 *
 * @author orjohan
 */
public final class Constants {
    //Pages
    public static final String Categories = "category";
    public static final String Login = "login";
    public static final String Register = "register";    
    
    //Session constants
    public static final String User = "user";
    public static final String Message = "msg";
    //Misc
    public static final String Resources = "res";
    public static final String BasePath = "/kiviq/";
    public static final String LoginServlet = "/login.do";
    
    //Requests equal to these strings are considered
    //public
    public static final String[] Public = {
      "login", "register", "", "/"
    };
    
    //Requests starting with these prefixes are considered
    //resources
    public static final String[] ResourceFiles = {
	"images/", "res/", "javax.faces.resource", "login.do", "searchprovider"
    };
    
    /**
     * Checks whether a requested file is public
     * or a resource, if the file is a resource file
     * no special action should be taken and the filtering
     * should be chained. If the file is public it should be forwarded
     * with a JSP-extension added.
     * If the file is private it should be forwarded with a jsf-extension
     * when the requested file is not the same as the actual file
     * 
     * @param page The requested file, relative to the application
     * base path (ie does not start with /kiviq)
     * @return null if the file is a resource file, true if the
     * file is public and false otherwise
     */
    public static Boolean isPublic(String page) {
        if (page.indexOf(Resources) == 0)
            return null;
        for (String s : ResourceFiles) {
	    if (page.indexOf(s) == 0)
		return null;
	}
	
        for (String s : Public)
            if (s.equals(page))
                return true;
        return false;
    }
}
